<?php
require_once 'BaseController.php';

/**
 * ASメンバーズ専用お問合せコントローラクラス<br />
 *
 * @package apamanshop
 * @author H.Imamura
 * @copyright (c) 2012 SystemSoft Corp. All rights reserved
 */
class Inquiry_AsmemberetcController extends Inquiry_BaseController
{
	/**
	 * インデックスアクション（入力画面）
	 *
	 * @access public
	 * @return void
	 */
	public function indexAction()
	{
		// 共通設定
		$this->setCommonConfig();
		
		//=====ブロック設定=====
		$this->setBlock($this->_asmemberetc_entry_helper);
		
		//=====表示=====
		$this->setXPassThroutgh();
		$this->display($this->_display_path);
	}
	
	/**
	 * 確認画面
	 *
	 * @access public
	 * @return void
	 */
	public function confAction()
	{
		// 共通設定
		$this->setCommonConfig();
		// 表示内容設定
		$this->convertForm();
		
		//=====ブロック設定=====
		$this->setBlock($this->_asmemberetc_conf_helper);
		
		//=====表示=====
		$this->setXPassThroutgh();
		$this->display($this->_display_path);
	}
	
	/**
	 * 送信処理
	 *
	 * @access public
	 * @return void
	 */
	public function sendAction()
	{
		// 送信内容設定
		//$this->setCommonConfig();
		$this->convertForm();
		$this->_data['TimeStr'] = date("Y/m/d H:i:s");
		
		// API呼び出し
		$result = $this->callInquiryApi('apiasmemberetc', array_merge($this->_params, $this->_data));
		
		//F5リロードによる２重送信防止のため完了画面表示にリダイレクト
		Apm_Util::redirect($this->_baseurl.'inquiry/asmemberetc/show/?ComId='.$this->_params['ComId'].'&result='.$result);
		return;
	}
	
	/**
	 * 送信完了画面
	 *
	 * @access public
	 * @return void
	 */
	public function showAction()
	{
		// 共通設定
		$this->setCommonConfig();
		
		//=====ブロック設定=====
		if ($this->_params['result'] == '' || $this->_params['result'] == '1') {
			$this->setBlock($this->_asmemberetc_send_helper);
		} else {
			$this->setBlock($this->_asmemberetc_error_helper);
		}
		
		//=====表示=====
		$this->setXPassThroutgh();
		$this->display($this->_display_path);
	}
	
	/**
	 * 共通設定
	 *
	 * @access private
	 * @return void
	 */
	private function setCommonConfig()
	{
		//表示テンプレートパス設定
		$this->_display_path = APPLICATION_PATH . '/modules/asnnet/views/scripts/base2.tpl';
		
		// JS
		$this->_script_helper = $this->_script_asmemberetc_helper;
		
		// パラメータマージ
		$this->_data = array_merge($this->_params, $this->_data);
		
		// 企業情報セット
		$this->setAsnComInfo($this->_params['ComId']);
	}
	
	/**
	 * 表示内容セット
	 *
	 * @access private
	 * @return void
	 */
	private function convertForm()
	{
		// 名前
		if (!empty($this->_params['NameSei']) && !empty($this->_params['NameMei'])) {
			$this->_data['Name'] = $this->_params['NameSei'] . '　' . $this->_params['NameMei'];
		} else {
			$this->_data['Name'] = $this->_params['NameSei'] . $this->_params['NameMei'];
		}
		// 年齢
		$this->_data['AgeNm'] = '';
		switch ($this->_params['AgeKbn']) {
			case '1':
				$this->_data['AgeNm'] = '18歳未満';
				break;
			case '2':
				$this->_data['AgeNm'] = '20歳未満';
				break;
			case '3':
				$this->_data['AgeNm'] = '20～24';
				break;
			case '4':
				$this->_data['AgeNm'] = '25～29';
				break;
			case '5':
				$this->_data['AgeNm'] = '30～34';
				break;
			case '6':
				$this->_data['AgeNm'] = '35～39';
				break;
			case '7':
				$this->_data['AgeNm'] = '40～49';
				break;
			case '8':
				$this->_data['AgeNm'] = '50～59';
				break;
			case '9':
				$this->_data['AgeNm'] = '60歳以上';
				break;
		}
		// 性別
		$this->_data['SexNm'] = '';
		if ($this->_params['Sex'] == '0') {
			$this->_data['SexNm'] = '男性';
		} else if ($this->_params['Sex'] == '1') {
			$this->_data['SexNm'] = '女性';
		}
		// 電話番号
		if (!empty($this->_params['Tel1']) && !empty($this->_params['Tel2']) && !empty($this->_params['Tel3'])) {
			$this->_data['Tel'] = $this->_params['Tel1'] . '-' . $this->_params['Tel2'] . '-' . $this->_params['Tel3'];
		} else {
			$this->_data['Tel'] = '';
		}
		// FAX
		if (!empty($this->_params['Fax1']) && !empty($this->_params['Fax2']) && !empty($this->_params['Fax3'])) {
			$this->_data['Fax'] = $this->_params['Fax1'] . '-' . $this->_params['Fax2'] . '-' . $this->_params['Fax3'];
		} else {
			$this->_data['Fax'] = '';
		}
		// お問い合わせ内容
		$this->_data['CommentStr'] = str_replace("\r","",str_replace("\n",'<br/>',$this->_params['Comment']));
	}
}
?>
